package com.bigger.arch.app.customer.client.Impl;

import com.bigger.arch.app.customer.client.IUserClient;
import com.bigger.arch.app.repository.model.UserModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;

@Service
public class UserClientImpl implements IUserClient {

    @Autowired
    RestTemplate restTemplate;

    public UserModel getItem(Integer id) {

        Map<String, Object> params = new HashMap<>();
        params.put("id", id);

        ResponseEntity<String> forEntity = restTemplate.getForEntity("http://bigger-app-service/user/getItem?id={id}", String.class, params);

        return restTemplate.getForEntity("http://bigger-app-service/user/getItem?id={id}", UserModel.class, params).getBody();
    }
}
